Ext.namespace("Task.ReviewPanel");

Task.ReviewPanel.panel = function() {
	Task.FeedBack.win.instance = new Task.FeedBack.win();
	
	this.txtTaskTitle = new Ext.form.TextField({
		width: 150
	});
	this.dtStart = new Ext.form.DateField({
		width: 150,
		format: 'Y-m-d'
	});
	this.dtEnd = new Ext.form.DateField({
		width: 150,
		format: 'Y-m-d'
	});
	/*this.cmStart = new Ext.form.DateField({
		width: 85,
		format: 'Y-m-d'
	});
	this.cmEnd = new Ext.form.DateField({
		width: 85,
		format: 'Y-m-d'
	});*/
	this.cbReviewTask = new Ext.form.Checkbox({
		inputValue: '1'
	});
    this.btnSearch = new Ext.Toolbar.Button({
        iconCls: 'icon-search',
        text: '回顾',
        tooltip: {text: '任务回顾'},
        handler: this.queryTask,
        scope: this
    });
    this.btnExportExcel = new Ext.Toolbar.Button({
        iconCls: 'icon-newplan',
        text: '导出Excel',
        tooltip: {text: '导出Excel'},
        handler: this.exportExcel,
        scope: this
    });
	this.store = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
			url: '../task/reviewTask.form?timesnap=' + Date.parse(new Date())
		}),
		reader: new Ext.data.JsonReader({
			root: 'result',
			totalProperty: 'total',
			fields: ['TASK_ID','TASK_EXE_ID','TASK_TITLE', 'TASK_DATE','USER_NAME','TASK_COMPLETE_DATE',
			 'TASK_DISPATCHER','TASK_CONTENT','TASK_STATUS','TASK_ORIGIN','TASK_NOTE','TASK_EXECUTOR',
			 'TASK_EXE_DISPATCHER_ID','TASK_EXE_USER_ID','TASK_EXE_STATUS','DIS_NAME','HAS_ACCESSORY']
		}),listeners:{
			 beforeload :{    
	    	  	fn : function(thiz,options){
       	          Ext.apply(thiz.baseParams,
       	          { 
       	          	 status:[0],
       	             taskTitle:this.txtTaskTitle.getValue(),
			  		 dtStart:this.dtStart.getValue()?this.dtStart.getValue().format('Y-m-d'):'',
			  		 dtEnd:this.dtEnd.getValue()?this.dtEnd.getValue().format('Y-m-d'):'',
			  		 //cmStart:this.cmStart.getValue()?this.cmStart.getValue().format('Y-m-d'):'',
			  		 //cmEnd:this.cmEnd.getValue()?this.cmEnd.getValue().format('Y-m-d'):'',
			  		 reviewTask:this.cbReviewTask.getValue()?'1':''
       	          });    
              },
              scope:this 
	    	}
		}
	});
	this.renderDays = function(value){
		var date = Date.parseDate(value.substring(0,10),"Y-m-d");
		var days = parseInt((date.getTime()-new Date().getTime())/(1000*60*60*24));
		if(days<0)
			return "<font color='red'>逾期"+(-days)+"天</font>";
		else
			return "<font size=1 >还剩"+days+"天</font>";
	};
	this.renderTaskStatus = function(value){
		return OMS.TASKSEXESTATUS[value];
	};
	this.renderOrigin = function(value){
		return OMS.TASKORIGIN[value];
	}
	this.sm =  new Ext.grid.CheckboxSelectionModel();
	this.colModel = new Ext.grid.ColumnModel({
	    defaults: {
	        width: 100,
	        sortable: true,
	        align: 'center'
	    },
	    columns: [
	    	this.sm ,
			{header: 'TASK_ID', width: 50, hidden: true, dataIndex: 'TASK_ID'},
			{header: '附件', width: 30, dataIndex: 'HAS_ACCESSORY',renderer:this.renderAccessory},
			{header: '任务名称', align:'left',width: 200, dataIndex: 'TASK_TITLE'},
			{header: '派发时间', dataIndex: 'TASK_DATE'},
			{header: '完成时限', dataIndex: 'TASK_COMPLETE_DATE'},
			{header: '执行人', dataIndex: 'USER_NAME'},
			{header: '剩余天数', dataIndex: 'TASK_COMPLETE_DATE',renderer:this.renderDays},
			{header: '任务状态', dataIndex: 'TASK_EXE_STATUS',renderer:this.renderTaskStatus},
			{header: '任务来源', dataIndex: 'TASK_ORIGIN',renderer:this.renderOrigin}
	    ]
	});
	
	this.gridPanel = new Ext.grid.GridPanel({
		region: 'center',
		cm:this.colModel,
		sm:this.sm ,
		store:this.store,
		loadMask: true,
		stripeRows: true, 
		tbar: [' 开始时间:', this.dtStart, '~', this.dtEnd, '未完成任务:',this.cbReviewTask,this.btnSearch,'-',this.btnExportExcel],
        loadMask: {msg: '加载中，请稍候...'},
        bbar:new Ext.PagingToolbar({
			 pageSize: 15,
	         store: this.store,
	         displayInfo: true,
	         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
	         emptyMsg: "没有记录..."
		}),
        viewConfig: { forceFit: true },
        listeners:{
      		  rowdblclick : function( grid, rowIndex,e){ 
        			Task.FeedBack.win.instance.initDetail(grid.store.getAt(rowIndex).data);
					Task.FeedBack.win.instance.show();
			}
       }
	});
	this.sendCon = new Ext.data.Connection({
		url:'../task/uptTaskExeStatus.form?timesnap=' + Date.parse(new Date()),
		method:'post'
	});
	Task.ReviewPanel.panel.superclass.constructor.call(this, {
		title:'任务回顾',
		layout:'border',
		items:[this.gridPanel],
		listeners:{
			render:this.queryTask
		}
	});
};
Ext.extend(Task.ReviewPanel.panel, Ext.Panel, {
	queryTask :function(){
		this.store.load({
			params:{
				start : 0,
				limit : 15,
				status:[0],
				 taskTitle:this.txtTaskTitle.getValue(),
			  	 dtStart:this.dtStart.getValue()?this.dtStart.getValue().format('Y-m-d'):'',
				 dtEnd:this.dtEnd.getValue()?this.dtEnd.getValue().format('Y-m-d'):'',
		  		 //cmStart:this.cmStart.getValue()?this.cmStart.getValue().format('Y-m-d'):'',
		  		 //cmEnd:this.cmEnd.getValue()?this.cmEnd.getValue().format('Y-m-d'):'',
		  		 reviewTask:this.cbReviewTask.getValue()?'1':''
				}
		});
	},
	exportExcel :function(){
		var dtStart = this.dtStart.getValue();
		var dtEnd = this.dtEnd.getValue();
		if(dtStart==''){
			alert("请选择开始日期");
		}else{
			var dtStart=this.dtStart.getValue()?this.dtStart.getValue().format('Y-m-d'):'';
			var dtEnd=this.dtEnd.getValue()?this.dtEnd.getValue().format('Y-m-d'):'';
			var reviewTask=this.cbReviewTask.getValue()?'1':'';
			var url='../task/exportReviewTask.form?dtStart='+dtStart+"&dtEnd="+dtEnd+"&reviewTask="+reviewTask;
			window.open(url,'_self') ; 
		}
	},
    renderAccessory : function(value) {
		if (value != null && value == '0') {
			return "@";
		} else {
			return "";
		}
	}
});


